What is @tiptap/extension-bubble-menu?
@tiptap/extension-bubble-menu is an extension for the Tiptap editor that provides a contextual menu (bubble menu) that appears when you select text. This menu can be customized to include various formatting options and actions, making it a powerful tool for enhancing the user experience in rich text editing.
What are @tiptap/extension-bubble-menu's main functionalities?
Basic Bubble Menu
This code sets up a basic bubble menu that appears when text is selected. The menu is linked to a DOM element with the class 'bubble-menu'.
import { BubbleMenu } from '@tiptap/extension-bubble-menu';
import { Editor } from '@tiptap/core';
import StarterKit from '@tiptap/starter-kit';
const editor = new Editor({
extensions: [
StarterKit,
BubbleMenu.configure({
element: document.querySelector('.bubble-menu'),
}),
],
});
Custom Bubble Menu
This code configures a custom bubble menu with additional Tippy.js options, such as setting the duration of the menu's appearance animation.
import { BubbleMenu } from '@tiptap/extension-bubble-menu';
import { Editor } from '@tiptap/core';
import StarterKit from '@tiptap/starter-kit';
const editor = new Editor({
extensions: [
StarterKit,
BubbleMenu.configure({
element: document.querySelector('.custom-bubble-menu'),
tippyOptions: {
duration: 100,
},
}),
],
});
Conditional Bubble Menu
This code sets up a bubble menu that only appears when there is a text selection (i.e., the selection is not empty).
import { BubbleMenu } from '@tiptap/extension-bubble-menu';
import { Editor } from '@tiptap/core';
import StarterKit from '@tiptap/starter-kit';
const editor = new Editor({
extensions: [
StarterKit,
BubbleMenu.configure({
element: document.querySelector('.conditional-bubble-menu'),
shouldShow: ({ state }) => {
return state.selection.empty === false;
},
}),
],
});
Other packages similar to @tiptap/extension-bubble-menu
prosemirror-menu
ProseMirror-menu is a menu system for the ProseMirror editor. It provides a way to create and manage menus that can be attached to the editor. Compared to @tiptap/extension-bubble-menu, ProseMirror-menu is more generic and requires more manual setup for contextual menus.
slate-react
Slate-react is a set of React components for the Slate editor. It allows for the creation of custom toolbars and menus, including bubble menus. While it offers similar functionality, it is designed specifically for use with the Slate editor and requires React.
Introduction
Tiptap is a headless wrapper around ProseMirror – a toolkit for building rich text WYSIWYG editors, which is already in use at many well-known companies such as New York Times, The Guardian or Atlassian.
Official Documentation
Documentation can be found on the Tiptap website.
License
Tiptap is open sourced software licensed under the MIT license.